package com.yl.controller;

import com.yl.utils.OssUtils;
import com.yl.utils.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/oss")
public class OssController {

    @Resource
    private OssUtils ossUtils;
    /**
     * 单个上传
     * @param file
     * @return
     */
    @PostMapping("/uploadOneFile")
    public R uploadFile(MultipartFile file) {
        //返回上传oss的url
        return ossUtils.uploadOneFile(file);
    }

    /**
     * 批量上传
     * @param files
     * @return
     */
    @PostMapping("/uploadArrayFile")
    public R uploadArrayFile(MultipartFile[] files) {
        //返回上传oss的url
        return ossUtils.uploadArrayFile(files);
    }

    /**
     * 删除照片
     * @param fileUrl
     * @return
     */
    @PostMapping("/deleteFile")
    public R deleteFile( String fileUrl) {
        //返回是否删除成功
        return ossUtils.deleteFile(fileUrl);
    }
}
